package com.neusoft.ysu.elm02.controller;


import com.neusoft.ysu.elm02.entity.CommonResult;
import com.neusoft.ysu.elm02.entity.Dept;
import com.neusoft.ysu.elm02.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：赵子鉴
 * @since 2023-08-18
 */
@CrossOrigin
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    IDeptService deptService;
    @PutMapping("/add")
    public CommonResult add(@RequestBody Dept dept){
//        考虑主键列的生成策略，为AUTO的时候必须设空
        dept.setDeptno(null);
        return deptService.insert(dept);
    }
    @DeleteMapping("/delete/{id}")
    public CommonResult deleteById(@PathVariable int id){
        return deptService.deleteById(id);
    }
    @PostMapping("/update")
    public CommonResult modDept(@RequestBody Dept dept){
        return deptService.update(dept);
    }
    @GetMapping("/q/all")
    public CommonResult findAll(){
        return deptService.selectAll();
    }
    @GetMapping("/q/byid/{id}")
    public CommonResult findById(@PathVariable int id){
        return deptService.selectById(id);
    }
    @GetMapping("/q/dname/{dname}")
    public CommonResult findDnameList(@PathVariable String dname){return deptService.findDnameList(dname);}


}
